<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>奇安药品数据中心</title>
    <link rel="stylesheet" href="/media/style.css">
</head>
<body>
<div class="container">
	<div class="top">
		<div class="qa_flex qa_cont">
			<div class="qa_lay logo">
                <h1><a href="/">奇安药品数据中心</a></h1>
			</div>
			<div class="qa_lay">
                <!-- 查询和新增表单 -->
                <form method="get">
                <div class="form">
			<!-- 下拉列表框 (变窄) -->
{#        <div class="label"><select name="category" class="form_select">#}
{#            <option value="">全部类别</option>#}
{#            <option value="X" {% if category == "X" %}selected{% endif %}>西药</option>#}
{#            <option value="Z" {% if category == "Z" %}selected{% endif %}>中成药</option>#}
{#            <option value="T" {% if category == "T" %}selected{% endif %}>中草药</option>#}
{#            <option value="J" {% if category == "J" %}selected{% endif %}>自制剂</option>#}
{#        </select></div>#}

        <!-- 查询框 -->
{#        <input type="text" name="search_query" class="form-control me-2" placeholder="查询医保码/品名/生产企业/批准文号" value="{{ search_query }}" style="width: 450px;">#}
                <div class="label"><input  type="text" name="search_query" id="search" class="form_input" placeholder="查询医保码/品名/条形码/生产企业/批准文号/追溯码"
                        value="{{ request.GET.search_query|default:'' }}" aria-label="查询" >
                    <button type="button" id="clear-button">×</button>
                </div>
        <!-- 查询按钮 -->
                <div class="label"><button type="submit" class="form_btn">查询</button></div>
                <div class="label"><p>共找到 <strong>{{ total_count }}</strong> 条记录</p></div>
                </div>
        <!-- 新增按钮 -->
{#        <a href="{% url 'gbzx_add' %}" class="btn btn-success">新增</a>#}
                </form>
            </div>
		</div>
	</div>
    <!-- 数据表 -->
	<div class="qa_cont qa_table">
		<div  class="qa_thead">
			<div class="qa_th th1">医保代码</div>
			<div class="qa_th th2">通用名称</div>
			<div class="qa_th th3">生产企业</div>
			<div class="qa_th th4">规格</div>
			<div class="qa_th th5">批准文号</div>
			<div class="qa_th th6">条形码</div>
			<div class="qa_th th7">追溯码</div>
			<div class="qa_th th8">图片</div>
            {#<div class="qa_th th9">操作</div>#}
		</div>
        <div class="qa_tbody">
            {% for item in page_obj %}
             <div class="qa_tr">
             {# <td  title="{{ item.ybm }}">{{ item.ybm }}</td>#}
				<div data-bt="医保代码" class="qa_td td1"><a href="{% url 'ptgb_detail' item.pta25 %}" title="{{ item.ybm }}">{{ item.ybm }}</a></div>
				<div data-bt="通用名称" class="qa_td td2" title="{{ item.a2 }}">{{ item.a2 }}</div>
				<div data-bt="生产企业" class="qa_td td3" title="{{ item.a8 }}">{{ item.a8|default_if_none:''  }}</div>
				<div data-bt="规格" class="qa_td td4" title="{{ item.a9 }}">{{ item.a9|default_if_none:'' }}</div>
				<div data-bt="批准文号" class="qa_td td5" title="{{ item.a29 }}">{{ item.a29|default_if_none:''  }}</div>
				<div data-bt="条形码" class="qa_td td6" title="{{ item.a40 }}">{{ item.a40|default_if_none:''  }}</div>
				<div data-bt="追溯码" class="qa_td td7" title="{{ item.zsm1 }}">{{ item.spbsm|default_if_none:''  }}</div>
{#				<div data-bt="图片" class="qa_td td8" title="{{ item.pic }}">{{ item.pic|default_if_none:''  }}</div>#}
                <div data-bt="图片数量" class="qa_td td8" title="" data-pics="{{ item.pic|default_if_none:'' }}">0</div>
			 </div>
{#                    <div data-bt="操作" class="qa_td td9">#}
{#                        <a href="{% url 'gbzx_edit' item.pk %}" class="btn btn-sm btn-warning">编辑</a>#}
{#                        <a href="{% url 'gbzx_delete' item.pk %}"#}
{#                           class="btn btn-sm btn-danger"#}
{#                           onclick="return confirm('确定要删除该记录吗？');">删除</a>#}
{#                    </div>#}
            {% endfor %}
        </div>
    <!-- 分页 -->
        <div class="pagination">
            <span class="step-links">
                {% if page_obj.has_previous %}
                    <a href="?page=1{{ tiaojian }}">第一页</a>
                    <a href="?page={{ page_obj.previous_page_number }}{{ tiaojian }}">上一页</a>
                {% endif %}

                <span class="current">
                    第 <strong>{{ page_obj.number }}</strong> 页，共 {{ page_obj.paginator.num_pages }} 页
                </span>

                {% if page_obj.has_next %}
                    <a href="?page={{ page_obj.next_page_number }}{{ tiaojian }}">下一页</a>
                    <a href="?page={{ page_obj.paginator.num_pages }}{{ tiaojian }}">最后一页</a>
                {% endif %}
            </span>
        </div>
    </div>
</div>
<script>
    document.addEventListener("DOMContentLoaded", function() {
        const picDivs = document.querySelectorAll('div[data-bt="图片数量"]');
        picDivs.forEach(function(div) {
            const pics = div.getAttribute('data-pics');
            if (pics && pics.trim() !== '') {
                // 将字符串按逗号分割，去除两端空白，并过滤掉空字符串
                const picList = pics.split(',').map(p => p.trim()).filter(p => p !== '');
                div.textContent = picList.length;
            } else {
                div.textContent = '0';
            }
        });
    });

    //搜索框加一键删除搜索内容
    document.getElementById('clear-button').addEventListener('click', function() {
    document.getElementById('search').value = ''; // 清空输入框
});
</script>
</body>
</html>